package com.atguigu.springboot.controller;

import com.atguigu.springboot.entity.User;
import com.atguigu.springboot.repository.UserRepository;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author : wenchao.long
 * @date : Created in 2020/11/25 20:44:36 周三
 * @description :
 */
@RestController
@RequestMapping("/user")
@AllArgsConstructor
public class UserController {
    private final UserRepository userRepository;

    @GetMapping()
    public User getById(@RequestParam("id") Integer id) {
        userRepository.getOne(id);
        return userRepository.findById(id).orElse(null);
    }

    @PutMapping()
    public User insert(@RequestBody User user) {
        return userRepository.save(user);
    }
}
